package com.web.portal.dao;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.web.portal.entity.Faculty;
import com.web.portal.entity.Lab;

@Repository (value="labDao")
public class LabDaoImpl extends WebportalBaseDao<Lab> implements LabDao {
	private static final Logger LOG=Logger.getLogger(LabDaoImpl.class);

	public List<Lab> listItems(Lab instance) {
		
			try {

				LOG.debug("Querying items from the list..........................");
				@SuppressWarnings("unchecked")
				List<Lab> result = (List<Lab>) getSession().createQuery(
						"from Lab").list();
				if (result == null) {
					LOG.debug("Empty result found");
					result = Collections.emptyList();
				}
				/*
				 * returning list from Criteria query
				 */

				LOG.debug("Querying items is successfully executed...........................");
				LOG.debug("Returning result...............");
				return result;
			} catch (RuntimeException e) {
				LOG.debug("unable to populate query " + e);
			}
			return null;
			
			}

	@Override
	protected void populateCriteria(
			Map<? extends Enum<?>, Object> searchCriteria, Criteria criteria) {
		if(searchCriteria.containsKey(LabSearchType.ID)){
			LOG.debug("key found for given lab map....................................");
			criteria.add(Restrictions.eq("id", searchCriteria.get(LabSearchType.ID)));
			
		}
		
	}

}
